<?php
import("data.db.content.DbContentUnit");

class DbIssue extends DbContentUnit {
	
	public $className = "data.logic.content.Issue";
	const CLASS_NAME = "data.logic.content.Issue";
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_issue";
	const TB_I			= 'iss';
	
	const TB_DATE		= 'iss_date';
	const TB_TITLE		= 'iss_title';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_id";}
	public static function _get_SUFFIX() {return self::TB_I;}
	//
	//
	function backwardForeignCollection() {
		return array("Item"=>"data.logic.content.IssueItem");
	}
	
	// properties
	public $date;
	public $title;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function getDate() {
		return $this->date;
	}
	function setDate($value) {
		$this->date = $value;
	}
	
	function getTitle() {
		return $this->title;
	}
	function setTitle($value) {
		$this->title = $value;
	}
	
	function setItems(&$items) {
		$this->backwardForeigns["Item"]->setList($items);
	}
	function getItems() {
		return $this->backwardForeigns["Item"]->getList();
	}
	
	// restore
	function fillEntity($arrResult) {
		DbAbstractTable::fillEntity($arrResult);
		$this->setDate($arrResult[self::TB_DATE]);
		$this->setTitle($arrResult[self::TB_TITLE]);
	}
	
	//store
	function fillFields() {
		DbAbstractTable::fillFields();
		$this->fildsForStore[self::TB_DATE] = "'".$this->getDate()."'";
		$this->fildsForStore[self::TB_TITLE] = "'".$this->getTitle()."'";
	}
	
	public static function findLast() {
		$arr = DbAbstractTable::__selectObjects(
			"SELECT * FROM ".self::TB_TABLENAME." order by iss_chdate desc limit 1",
			self::CLASS_NAME
		);
		return (isset($arr[0])?$arr[0]:null);
	}
	
	// same for all classes
	public static function findAll() {return DbAbstractTable::findAll(self::CLASS_NAME);}
    public static function findById($id) {return DbAbstractTable::findById($id, self::CLASS_NAME);}
}
?>